package com.huawei.appmarket.service.settings.view.activity;

import android.content.Intent;
import android.os.Bundle;
import android.text.TextUtils;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.LinearLayout;
import androidx.annotation.Nullable;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;
import com.huawei.appgallery.foundation.account.bean.UserSession;
import com.huawei.appgallery.foundation.ui.framework.activity.BaseActivity;
import com.huawei.appgallery.serverreqkit.api.bean.ResponseBean;
import com.huawei.appgallery.serverreqkit.api.listener.IServerCallBack;
import com.huawei.appmarket.service.settings.bean.gameservice.AuthorizedAppInfo;
import com.huawei.appmarket.service.settings.bean.gameservice.GetGameServiceAuthAppListRes;
import com.huawei.hwid.core.constants.HwAccountConstants;
import com.huawei.secure.android.common.intent.SafeIntent;
import java.lang.ref.WeakReference;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import o.BaseRequest;
import o.der.a;
import o.der.f;
import o.der.g;
import o.Logger;
import o.doo;
import o.ContentManager;
import o.efv;
import o.ehe;
import o.eoh;
import o.eol;
import o.eon;
import o.evk;
import o.fbh;

public class ShowGameServiceAuthAppsActivity extends BaseActivity implements o.ehe.d {
    private ehe ˏॱ;
    private String ͺ;
    private List<AuthorizedAppInfo> ॱˊ = new ArrayList();

    static class b implements IServerCallBack {
        private WeakReference<ShowGameServiceAuthAppsActivity> ˊ;

        private b(ShowGameServiceAuthAppsActivity showGameServiceAuthAppsActivity) {
            this.ˊ = new WeakReference(showGameServiceAuthAppsActivity);
        }

        public void prePostResult(BaseRequest o_cvu, ResponseBean responseBean) {
        }

        public void notifyResult(BaseRequest o_cvu, ResponseBean responseBean) {
            ShowGameServiceAuthAppsActivity showGameServiceAuthAppsActivity = (ShowGameServiceAuthAppsActivity) this.ˊ.get();
            if (showGameServiceAuthAppsActivity == null || showGameServiceAuthAppsActivity.isFinishing()) {
                Logger.ˋ("ShowGameServiceAuthAppsActivity", "StoreCallbackHandler meet invalid activity");
            } else if (!(responseBean instanceof GetGameServiceAuthAppListRes) || responseBean.getResponseCode() != 0) {
            } else {
                if (responseBean.getRtnCode_() == 0) {
                    showGameServiceAuthAppsActivity.ॱˊ.clear();
                    showGameServiceAuthAppsActivity.ॱˊ.addAll(((GetGameServiceAuthAppListRes) responseBean).ˏ());
                    showGameServiceAuthAppsActivity.ᐝॱ();
                    showGameServiceAuthAppsActivity.ˏॱ.ˊ();
                } else if (responseBean.getRtnCode_() == 2) {
                    Logger.ˏ("ShowGameServiceAuthAppsActivity", "invalid AT, signIn again");
                    showGameServiceAuthAppsActivity.ʼॱ();
                }
            }
        }
    }

    static class d implements eol {
        private WeakReference<ShowGameServiceAuthAppsActivity> ˊ;

        private d(ShowGameServiceAuthAppsActivity showGameServiceAuthAppsActivity) {
            this.ˊ = new WeakReference(showGameServiceAuthAppsActivity);
        }

        public void ॱ(int i) {
            eon.ॱ().ˊ("ShowGameServiceAuthAppsActivity");
            ShowGameServiceAuthAppsActivity showGameServiceAuthAppsActivity = (ShowGameServiceAuthAppsActivity) this.ˊ.get();
            if (showGameServiceAuthAppsActivity == null || showGameServiceAuthAppsActivity.isFinishing()) {
                Logger.ˋ("ShowGameServiceAuthAppsActivity", "SignInObserverHandler meet invalid activity");
            } else if (i == 300) {
                Logger.ˎ("ShowGameServiceAuthAppsActivity", "Get signIn success message");
                showGameServiceAuthAppsActivity.ॱˊ();
            }
        }
    }

    public void onCreate(@Nullable Bundle bundle) {
        Logger.ˎ("ShowGameServiceAuthAppsActivity", "onCreate");
        super.onCreate(bundle);
        getWindow().setBackgroundDrawableResource(a.ᐝ);
        setContentView(g.ॱˊ);
        ॱ(getString(f.ॱᐧ));
        ᐝ();
        this.ͺ = new SafeIntent(getIntent()).getStringExtra("gameService.cancelAppId");
        if (!TextUtils.isEmpty(this.ͺ)) {
            Logger.ˎ("ShowGameServiceAuthAppsActivity", "get cancel appId: " + this.ͺ);
        }
        setResult(2022);
    }

    private void ᐝ() {
        RecyclerView recyclerView = (RecyclerView) findViewById(o.der.d.ʻʼ);
        recyclerView.setLayoutManager(new LinearLayoutManager(this));
        this.ˏॱ = new ehe(this, this.ॱˊ);
        this.ˏॱ.ˎ(this);
        recyclerView.setAdapter(this.ˏॱ);
        ((LinearLayout) findViewById(o.der.d.ˆ)).setOnClickListener(new OnClickListener(this) {
            final /* synthetic */ ShowGameServiceAuthAppsActivity ˎ;

            {
                this.ˎ = r1;
            }

            public void onClick(View view) {
                this.ˎ.startActivity(new Intent(this.ˎ, SettingGameServiceActivity.class));
            }
        });
    }

    public void onResume() {
        super.onResume();
        ͺ();
    }

    private void ͺ() {
        if (doo.ˊ(this)) {
            CharSequence accessToken = UserSession.getInstance().getAccessToken();
            Logger.ˎ("ShowGameServiceAuthAppsActivity", "accessToken: " + (accessToken == null ? HwAccountConstants.NULL : "not null"));
            if (TextUtils.isEmpty(accessToken)) {
                ʼॱ();
                return;
            } else {
                ॱˊ();
                return;
            }
        }
        Logger.ˎ("ShowGameServiceAuthAppsActivity", "no active network");
        evk.ˏ(ContentManager.getInstant().getContext(), f.ʻʽ, 0).ˋ();
    }

    private void ॱˊ() {
        if (doo.ˊ(this)) {
            fbh.ˋ(efv.ˊ(UserSession.getInstance().getAccessToken()), new b());
            return;
        }
        Logger.ˎ("ShowGameServiceAuthAppsActivity", "no active network");
        evk.ˏ(ContentManager.getInstant().getContext(), f.ʻʽ, 0).ˋ();
    }

    private void ᐝॱ() {
        if (!TextUtils.isEmpty(this.ͺ)) {
            Collection arrayList = new ArrayList();
            for (AuthorizedAppInfo authorizedAppInfo : this.ॱˊ) {
                if (authorizedAppInfo.ˊ().equals(this.ͺ)) {
                    arrayList.add(authorizedAppInfo);
                    break;
                }
            }
            this.ॱˊ.clear();
            if (!arrayList.isEmpty()) {
                this.ॱˊ.addAll(arrayList);
            }
        }
    }

    public void ˊ(boolean z) {
        Logger.ˎ("ShowGameServiceAuthAppsActivity", "onResult: isSuccess=" + z);
        if (!TextUtils.isEmpty(this.ͺ)) {
            setResult(z ? 2021 : 2022);
        }
    }

    private void ʼॱ() {
        eon.ॱ().ˎ("ShowGameServiceAuthAppsActivity", new d());
        new eoh().ˎ();
    }

    public void onDestroy() {
        eon.ॱ().ˊ("ShowGameServiceAuthAppsActivity");
        this.ˏॱ.ॱ();
        super.onDestroy();
    }
}
